# coding:utf8

class HtmlOutputer(object):
	"""docstring for HtmlOutputer"""
	def __init__(self):
		self.datas = []

	def collect_data(self, data):
		if data is None:
			return
		self.datas.append(data)

	def show_datas(self):
		fout = open('output.html', 'w', encoding="utf-8")

		fout.write("<html>")
		fout.write("<meta charset='utf-8'>")
		fout.write("<div style='text-align: center;'><h2>百科爬虫展示</h2></div>")

		fout.write("<div>")
		fout.write("<table>")
		fout.write("<thead><th>词条</th><th>简介</th><th>图片</th></thead>")

		for data in self.datas:
			fout.write("<tr>")
			fout.write("<td style='width:100px'><a href='%s'>%s</a></td>"%(data['url'], data['title']))
			fout.write("<td>%s</td>"%(data['summary']))
			fout.write("<td><img style='width:150px' src='%s'/></td>"%(data['summary_pic']))
			fout.write("</tr>")

		fout.write("<table>")
		fout.write("</div>")

		fout.write("</html>")
		fout.close()
